home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_readline.idb / usr / freeware / include / readline / history.h.z / history.h
Encoding:
C/C++ Source or Header  |  1999-04-16  |  9.0 KB  |  249 lines

  1. /* History.h -- the names of functions that you can call in history. */
  2. /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
  3.  
  4.    This file contains the GNU History Library (the Library), a set of
  5.    routines for managing the text of previously typed lines.
  6.  
  7.    The Library is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 1, or (at your option)
  10.    any later version.
  11.  
  12.    The Library is distributed in the hope that it will be useful, but
  13.    WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.    General Public License for more details.
  16.  
  17.    The GNU General Public License is often shipped with GNU software, and
  18.    is generally kept in a file called COPYING or LICENSE.  If you do not
  19.    have a copy of the license, write to the Free Software Foundation,
  20.    675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. #ifndef _HISTORY_H_
  23. #define _HISTORY_H_
  24.  
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28.  
  29. #if defined READLINE_LIBRARY
  30. #  include "rlstdc.h"
  31. #else
  32. #  include <readline/rlstdc.h>
  33. #endif
  34.  
  35. #if !defined (_FUNCTION_DEF)
  36. #  define _FUNCTION_DEF
  37. typedef int Function ();
  38. typedef void VFunction ();
  39. typedef char *CPFunction ();
  40. typedef char **CPPFunction ();
  41. #endif
  42.  
  43. #ifdef __STDC__
  44. typedef void *histdata_t;
  45. #else
  46. typedef char *histdata_t;
  47. #endif
  48.  
  49. /* The structure used to store a history entry. */
  50. typedef struct _hist_entry {
  51.   char *line;
  52.   histdata_t data;
  53. } HIST_ENTRY;
  54.  
  55. /* A structure used to pass the current state of the history stuff around. */
  56. typedef struct _hist_state {
  57.   HIST_ENTRY **entries;        /* Pointer to the entries themselves. */
  58.   int offset;            /* The location pointer within this array. */
  59.   int length;            /* Number of elements within this array. */
  60.   int size;            /* Number of slots allocated to this array. */
  61.   int flags;
  62. } HISTORY_STATE;
  63.  
  64. /* Flag values for the `flags' member of HISTORY_STATE. */
  65. #define HS_STIFLED    0x01
  66.  
  67. /* Initialization and state management. */
  68.  
  69. /* Begin a session in which the history functions might be used.  This
  70.    just initializes the interactive variables. */
  71. extern void using_history __P((void));
  72.  
  73. /* Return the current HISTORY_STATE of the history. */
  74. extern HISTORY_STATE *history_get_history_state __P((void));
  75.  
  76. /* Set the state of the current history array to STATE. */
  77. extern void history_set_history_state __P((HISTORY_STATE *));
  78.  
  79. /* Manage the history list. */
  80.  
  81. /* Place STRING at the end of the history list.
  82.    The associated data field (if any) is set to NULL. */
  83. extern void add_history __P((char *));
  84.  
  85. /* A reasonably useless function, only here for completeness.  WHICH
  86.    is the magic number that tells us which element to delete.  The
  87.    elements are numbered from 0. */
  88. extern HIST_ENTRY *remove_history __P((int));
  89.  
  90. /* Make the history entry at WHICH have LINE and DATA.  This returns
  91.    the old entry so you can dispose of the data.  In the case of an
  92.    invalid WHICH, a NULL pointer is returned. */
  93. extern HIST_ENTRY *replace_history_entry __P((int, char *, histdata_t));
  94.  
  95. /* Clear the history list and start over. */
  96. extern void clear_history __P((void));
  97.  
  98. /* Stifle the history list, remembering only MAX number of entries. */
  99. extern void stifle_history __P((int));
  100.  
  101. /* Stop stifling the history.  This returns the previous amount the
  102.    history was stifled by.  The value is positive if the history was
  103.    stifled, negative if it wasn't. */
  104. extern int unstifle_history __P((void));
  105.  
  106. /* Return 1 if the history is stifled, 0 if it is not. */
  107. extern int history_is_stifled __P((void));
  108.  
  109. /* Information about the history list. */
  110.  
  111. /* Return a NULL terminated array of HIST_ENTRY which is the current input
  112.    history.  Element 0 of this list is the beginning of time.  If there
  113.    is no history, return NULL. */
  114. extern HIST_ENTRY **history_list __P((void));
  115.  
  116. /* Returns the number which says what history element we are now
  117.    looking at.  */
  118. extern int where_history __P((void));
  119.   
  120. /* Return the history entry at the current position, as determined by
  121.    history_offset.  If there is no entry there, return a NULL pointer. */
  122. HIST_ENTRY *current_history __P((void));
  123.  
  124. /* Return the history entry which is logically at OFFSET in the history
  125.    array.  OFFSET is relative to history_base. */
  126. extern HIST_ENTRY *history_get __P((int));
  127.  
  128. /* Return the number of bytes that the primary history entries are using.
  129.    This just adds up the lengths of the_history->lines. */
  130. extern int history_total_bytes __P((void));
  131.  
  132. /* Moving around the history list. */
  133.  
  134. /* Set the position in the history list to POS. */
  135. int history_set_pos __P((int));
  136.  
  137. /* Back up history_offset to the previous history entry, and return
  138.    a pointer to that entry.  If there is no previous entry, return
  139.    a NULL pointer. */
  140. extern HIST_ENTRY *previous_history __P((void));
  141.  
  142. /* Move history_offset forward to the next item in the input_history,
  143.    and return the a pointer to that entry.  If there is no next entry,
  144.    return a NULL pointer. */
  145. extern HIST_ENTRY *next_history __P((void));
  146.  
  147. /* Searching the history list. */
  148.  
  149. /* Search the history for STRING, starting at history_offset.
  150.    If DIRECTION < 0, then the search is through previous entries,
  151.    else through subsequent.  If the string is found, then
  152.    current_history () is the history entry, and the value of this function
  153.    is the offset in the line of that history entry that the string was
  154.    found in.  Otherwise, nothing is changed, and a -1 is returned. */
  155. extern int history_search __P((char *, int));
  156.  
  157. /* Search the history for STRING, starting at history_offset.
  158.    The search is anchored: matching lines must begin with string.
  159.    DIRECTION is as in history_search(). */
  160. extern int history_search_prefix __P((char *, int));
  161.  
  162. /* Search for STRING in the history list, starting at POS, an
  163.    absolute index into the list.  DIR, if negative, says to search
  164.    backwards from POS, else forwards.
  165.    Returns the absolute index of the history element where STRING
  166.    was found, or -1 otherwise. */
  167. extern int history_search_pos __P((char *, int, int));
  168.  
  169. /* Managing the history file. */
  170.  
  171. /* Add the contents of FILENAME to the history list, a line at a time.
  172.    If FILENAME is NULL, then read from ~/.history.  Returns 0 if
  173.    successful, or errno if not. */
  174. extern int read_history __P((char *));
  175.  
  176. /* Read a range of lines from FILENAME, adding them to the history list.
  177.    Start reading at the FROM'th line and end at the TO'th.  If FROM
  178.    is zero, start at the beginning.  If TO is less than FROM, read
  179.    until the end of the file.  If FILENAME is NULL, then read from
  180.    ~/.history.  Returns 0 if successful, or errno if not. */
  181. extern int read_history_range __P((char *, int, int));
  182.  
  183. /* Write the current history to FILENAME.  If FILENAME is NULL,
  184.    then write the history list to ~/.history.  Values returned
  185.    are as in read_history ().  */
  186. extern int write_history __P((char *));
  187.  
  188. /* Append NELEMENT entries to FILENAME.  The entries appended are from
  189.    the end of the list minus NELEMENTs up to the end of the list. */
  190. int append_history __P((int, char *));
  191.  
  192. /* Truncate the history file, leaving only the last NLINES lines. */
  193. extern int history_truncate_file __P((char *, int));
  194.  
  195. /* History expansion. */
  196.  
  197. /* Expand the string STRING, placing the result into OUTPUT, a pointer
  198.    to a string.  Returns:
  199.  
  200.    0) If no expansions took place (or, if the only change in
  201.       the text was the de-slashifying of the history expansion
  202.       character)
  203.    1) If expansions did take place
  204.   -1) If there was an error in expansion.
  205.    2) If the returned line should just be printed.
  206.  
  207.   If an error ocurred in expansion, then OUTPUT contains a descriptive
  208.   error message. */
  209. extern int history_expand __P((char *, char **));
  210.  
  211. /* Extract a string segment consisting of the FIRST through LAST
  212.    arguments present in STRING.  Arguments are broken up as in
  213.    the shell. */
  214. extern char *history_arg_extract __P((int, int, char *));
  215.  
  216. /* Return the text of the history event beginning at the current
  217.    offset into STRING.  Pass STRING with *INDEX equal to the
  218.    history_expansion_char that begins this specification.
  219.    DELIMITING_QUOTE is a character that is allowed to end the string
  220.    specification for what to search for in addition to the normal
  221.    characters `:', ` ', `\t', `\n', and sometimes `?'. */
  222. extern char *get_history_event __P((char *, int *, int));
  223.  
  224. /* Return an array of tokens, much as the shell might.  The tokens are
  225.    parsed out of STRING. */
  226. extern char **history_tokenize __P((char *));
  227.  
  228. /* Exported history variables. */
  229. extern int history_base;
  230. extern int history_length;
  231. extern int max_input_history;
  232. extern char history_expansion_char;
  233. extern char history_subst_char;
  234. extern char history_comment_char;
  235. extern char *history_no_expand_chars;
  236. extern char *history_search_delimiter_chars;
  237. extern int history_quotes_inhibit_expansion;
  238.  
  239. /* If set, this function is called to decide whether or not a particular
  240.    history expansion should be treated as a special case for the calling
  241.    application and not expanded. */
  242. extern Function *history_inhibit_expansion_function;
  243.  
  244. #ifdef __cplusplus
  245. }
  246. #endif
  247.  
  248. #endif /* !_HISTORY_H_ */
  249.